package statistics;

public abstract class AbstractStatisticTests 
{
	
	public int[][][] make3DArray ( int[] singleD ) 
	{
		int[][][] multiD = new int[2][2][2];
		multiD[1][1][1] = singleD[3];
		multiD[1][1][0] = singleD[2];
		multiD[1][0][1] = singleD[1];
		multiD[1][0][0] = singleD[0];
		return multiD; 
	}
	
	public int[] make1DArray ( int[][][] multiD  ) 
	{
		int[] singleD = new int[4];
		singleD[3] = multiD[1][1][1];
		singleD[2] = multiD[1][1][0];
		singleD[1] = multiD[1][0][1];
		singleD[0] = multiD[1][0][0];
		return singleD;		
	}
	

	public double[][][] computeExpectations(int[][][] observations)
	{ 
		int total = observations[1][1][1] + observations[1][1][0] + observations[1][0][1] + observations[1][0][0];
		double P = (double) ( observations[1][1][1] + observations[1][1][0] ) / total;		
		double Q = (double) ( observations[1][1][1] + observations[1][0][1] ) / total;
		
		double[][][] expectations = new double[2][2][2];
		expectations[1][1][1] = P * Q * total;
		expectations[1][1][0] = P * (1-Q) * total;
		expectations[1][0][1] = (1-P) * Q * total;
		expectations[1][0][0] = (1-P) * (1-Q) * total;
		
		return expectations;
	}
	
}
